import {
  mapState,
  mapMutations,
  mapActions
} from "vuex";

import {
  getmessage_count,
} from "@/assets/api/userCenterApi";

import {
  getUserActivity,
  getwendawindow,
} from "@/assets/api/indexApi";

import {
  getDiffDay
} from "@/assets/utils/utils.js";


export default {
  data() {
    return {
      CouponShow: false,
      getAdminCoupon: 0,
      getDiscountSwitch: true,
    };
  },
  computed: {
    ...mapState("common", {
      userInfo: (state) => state.userInfo
    }),
  },
  mounted() {
    if (!this.userInfo) {
      this.openWebPage();
    }
  },
  methods: {

    ...mapMutations("quiz", ["set_entering"]),
    ...mapActions("common", [
      "getUserInfo2",
    ]),

    // 打开页面检查是否登录，登录后做相应处理
    openWebPage(is = false) {
      if (localStorage.getItem("token")) {
        let that = this;
        setTimeout(() => {
          that.getUserInfo2()
            .then((user) => {
              if (user) {

                // 还要做个优惠券领取弹窗操操操
                if (user.activity_reward == '1') that.getDiscount();
              }
            })
            .catch(() => {});
        }, 100);
      }
    },

    // 去掉奖励弹窗
    async getDiscount() {

      if (this.getDiscountSwitch == false) return;
      this.getDiscountSwitch = false;
      const res = await getUserActivity({
        activity_id: 1,
      });

      setTimeout(() => {
        this.getDiscountSwitch = true;
        this.getwendawindow();
      }, 800);
    },

    // 获取问答优惠券
    async getwendawindow() {
      const res = await getwendawindow({});
      if (res.code == 1 && res.data > 0) {
        this.getAdminCoupon = res.data;
        this.CouponShow = true;
      }
    },

  }
};
